package com.thousandsunny.consumer;


import org.apache.commons.lang3.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE;
import static org.springframework.web.bind.annotation.RequestMethod.GET;

/**
 * @author Savitar
 */
@RefreshScope
@RestController
@RequestMapping(value = "user", produces = APPLICATION_JSON_UTF8_VALUE)
public class UserController {
    @Autowired
    private UserService userService;
    @Value("${name}")
    private String name;

    @RequestMapping(value = "/detail", method = GET)
    @PreAuthorize("hasAuthority('admin')")
    public void userDetail() {
        System.out.println("===========" + System.currentTimeMillis() + name);
        System.out.println(userService.detail(RandomUtils.nextInt(1,11)));
    }
}
